package com.leyou.trade.web;

import com.leyou.trade.entity.carts;
import com.leyou.trade.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cart")
public class CartController {
    @Autowired
    private CartService cartService;
    /**
     * 加入购物车
     * @return
     */
    @PostMapping
    public ResponseEntity<Void> addCarts(@RequestBody carts carts){
        cartService.addCarts(carts);
    return ResponseEntity.status(HttpStatus.CREATED).build();
    }

    /**
     * 查询购物车
     * @return
     */
    @GetMapping("/list")
    public ResponseEntity<List<carts>> listCarts(){
        return ResponseEntity.ok(cartService.listCarts());
    }

    @DeleteMapping("{skuId}")
    public ResponseEntity<Void> deleteCart(@PathVariable("skuId") Long skuId){
        cartService.deletaCart(skuId);
        return ResponseEntity.ok().build();
    }
}
